package com.deep.deepenterprise.task.config;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * @author xyz
 * @version 1.0
 * @title DrScheduleConfig
 * @description
 * @create 2024/5/11 13:28
 */
@Configuration
public class DrScheduleConfig implements SchedulingConfigurer {
    @Override
    public void configureTasks(@NotNull ScheduledTaskRegistrar taskRegistrar) {
        ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
        // 设置线程池数量
        executor.setPoolSize(4);
        // 设置默认线程名称
        executor.setThreadNamePrefix("scheduled-");
        // 等待所有任务结束后再关闭线程池
        executor.setWaitForTasksToCompleteOnShutdown(true);
        // 线程初始化
        executor.initialize();
        taskRegistrar.setScheduler(executor);
    }
}
